home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Abalone 1.4.2 / src / Rules.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-21  |  3.8 KB  |  141 lines  |  [TEXT/MPS ]

  1. #ifndef RULES_H
  2. #define RULES_H
  3.  
  4. #ifndef THINK_C
  5. #include <Types.h>
  6. #endif
  7.  
  8. #define kFields            61
  9. #define kDirections        6
  10. #define kVictory        6
  11. #define kPlayers        3
  12.  
  13.  
  14. enum _directions
  15. {
  16.     right,
  17.     botright,
  18.     botleft,
  19.     left,
  20.     topleft,
  21.     topright,
  22.     down        /*    off the board */
  23. };
  24.  
  25.  
  26. enum _result
  27. {
  28.     normal_move = 0, ball_down
  29. };
  30.  
  31.  
  32. enum _owner
  33. {
  34.     empty,
  35.     blak,
  36.     whit,
  37.     grin
  38. };
  39.  
  40.  
  41. //    Fields are numbered starting at 1; 0 is used for 'not on the board'.
  42. //    The actual number of fields on the board is kFields, but the first field isn't
  43. //    used so the number of a field can be used as an index.
  44.  
  45. typedef unsigned char    Arrow;
  46. typedef    unsigned char    Field;
  47. typedef Field            Fields[kFields+1],                *FieldsPtr;
  48. typedef unsigned char    Loot[kPlayers][kVictory+1],        *LootPtr;
  49.                     //    The balls currently won by the players.
  50.                     //    updated in DoMove.
  51.                     //    Loot[<player>-1][<ball>]        ::= color of victim for ball # <ball>
  52.                     //    Special case:
  53.                     //    Loot[<player>-1][0]                ::=    total # balls pushed off by <player>
  54.  
  55. typedef struct _board
  56. {
  57.     Fields            field;
  58.     Loot            loot;
  59.     unsigned char    players;
  60.     
  61. }    Board, *BoardPtr;
  62.  
  63.  
  64. typedef unsigned char    MoveData[4], *MovePtr;    //    first three for fields, last for direction
  65.  
  66.  
  67.         // the following defines should have been functions for safety, but this is faster.
  68.         // The tables should be initialised before use by calling InitRules
  69.  
  70. #define     Neighbour(field,direction)        (_neighbour[(field)][(direction)])
  71.         //    Returns the neighbour of a field in a specified direction, or 0 if nonexistant
  72.         
  73. #define     Neighbours(field1,field2)        (_neighbours[(field1)][(field2)])
  74.         //    Are the fields neighbours?
  75.         
  76. #define     Direction(from,to)                (_direction[(from)][(to)])
  77.         //    Returns the direction from one field to another if neighbours, down otherwise
  78.  
  79. #define     Distance(field,direction)        (_distance[(field)][(direction)])
  80.         //    Returns the distance from the edge in a certain direction
  81.  
  82. void        InitRules (void);
  83.         //    Initialise the tables for the defines above.
  84.         //    Should be called before using any one of them.
  85.  
  86. void        ResetBoard (BoardPtr);
  87.         //    Reset the board data structur to the initial position.
  88.  
  89. Field        LocToField (short h, short v);
  90.         //    Convert local coordinates to field number.
  91.  
  92. short        DoMove (BoardPtr board, MovePtr move);
  93. short        DoFlicheMove (BoardPtr board, MovePtr move);
  94.         //    Do administration involved with a move.
  95.         //    Nothing else (sound, updates etc.) is done,
  96.         //    so the function can be used in move evaluations.
  97.  
  98. short        BallsWon (BoardPtr board, short player);
  99.         //    Count the number of balls the given player has won from the other player(s)
  100.     
  101. #define     NextPlayer(current) (((current) % gTheGame.Players) + 1)
  102. #define     PriorPlayer(current) ((current + gTheGame.Players - 1) % gTheGame.Players)
  103.         //    Returns the next player for the given one
  104.         //    not a function to save function call overhead
  105.  
  106. Boolean        ValidMove (BoardPtr board, MovePtr move);
  107. Boolean     ValidFliche (BoardPtr board, FieldsPtr field);
  108. Boolean     ValidFlicheSorted (BoardPtr board, FieldsPtr field);
  109. Boolean        ValidFlicheMove (BoardPtr board, MovePtr move);
  110. Boolean        ValidFlicheMoveSorted (BoardPtr board, MovePtr move);
  111.         //    Test possible selections/moves for validity.
  112.         //    Normally, the 'unsorted' functions should be used,
  113.         //    the 'sorted' varieties assume the move is presented to them 'sort3' sorted
  114.  
  115.  
  116. #ifdef RULES_C
  117.  
  118. #include "Error.h"
  119. #include "Game.h"
  120. #include "Global.h"
  121. #include "Settings.h"
  122.  
  123.  
  124. void sort3 (FieldsPtr fields);
  125. short        DoPropMove (BoardPtr board, Field f, Arrow direction);
  126.  
  127. #else
  128.  
  129. //    These tables must be exported for the defines above to work.
  130. //    Logically, they're local to this module; they're exported for efficiency.
  131. //    Do not modify elsewhere!
  132.  
  133. extern Field            _neighbour        [kFields+1] [kDirections+1];
  134. extern Boolean            _neighbours        [kFields+1] [kFields+1];
  135. extern Arrow            _direction        [kFields+1] [kFields+1];
  136. extern unsigned char    _distance        [kFields+1] [kDirections];
  137.  
  138. #endif
  139.  
  140.  
  141. #endif